/* eslint-disable */
import ttsRecorder from './tts-recorder.js'

export let voiceQueue = []
export let canVoiceToPlay = true



/**
 * 播报
 * @param text
 * @param callback
 */
export function playAideo(text, callback) {
    setVoiceQueue('push', text)
    ttsRecorder.setCallBackFun(callback)
    if (voiceQueue.length) {
        toPlay(voiceQueue[0])
    }
}

export function toPlay(text) {
  ttsRecorder.setParams({
    text
  })
  if (['init', 'endPlay', 'errorTTS'].includes(ttsRecorder.status)) {
    ttsRecorder.start()
  } else {
    ttsRecorder.stop()
  }
}

export function setVoiceQueue(type, text) {
  switch (type) {
  case 'push':
    voiceQueue.push(text)
    break
  case 'split':
    voiceQueue.splice(0, 1)
    break
  }
}

export function setCanVoiceToPlay(bol) {
  canVoiceToPlay = bol
}
